package com.zznj.xzjc.adapter.index;

import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zznj.xzjc.R;
import com.zznj.xzjc.net.entity.DictionaryBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/7
 */
public class DicByslAdapter extends BaseQuickAdapter<DictionaryBean, BaseViewHolder> {

    public DicByslAdapter(int layoutResId, @Nullable List<DictionaryBean> data) {
        super(layoutResId, data);
    }

    private int selectPosition = -1;
    private ArrayList<String> selectPositonList = new ArrayList<>();
    public void setSelectPosition(int position){
        this.selectPosition = position;
        notifyDataSetChanged();
    }

    public void setSelectPositions(int position){
        if(selectPositonList.contains(position+"")){
            selectPositonList.remove(position+"");
        }else{
            selectPositonList.add(position+"");
        }
        notifyDataSetChanged();
    }

    public ArrayList<String> getSelectPositions(){
        return selectPositonList;
    }

    @Override
    protected void convert(BaseViewHolder helper, DictionaryBean item) {
        TextView content = helper.getView(R.id.content);
        content.setText(item.getItemName());
        ImageView selectImage = helper.getView(R.id.selectImage);
        if(helper.getAdapterPosition() == selectPosition){
            selectImage.setImageResource(R.mipmap.gyss_ic_bysl_select_press);
        }else{
            selectImage.setImageResource(R.mipmap.gyss_ic_bysl_select_normal);
        }

        if(selectPositonList.contains(helper.getAdapterPosition()+"")){
            selectImage.setImageResource(R.mipmap.gyss_ic_bysl_select_press);
        }else{
            selectImage.setImageResource(R.mipmap.gyss_ic_bysl_select_normal);
        }
    }
}
